package com.ctg.payroll2.action.xlsImport;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.ctg.payroll2.bean.po.SysUser;
import com.ctg.payroll2.service.xlsImport.XlsImportService;
import com.ctg.payroll2.util.Constants;
import com.ctg.platform.util.Page;
import com.ctg.platform.util.Parse;
import com.googlecode.jsonplugin.annotations.JSON;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("unchecked")
public class PayInPutOpActoin extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3097904332677627350L;

	private XlsImportService xlsImportService;

	private Page Plist;

	private Page Slist;

	public Page getPlist() {
		return Plist;
	}

	public void setPlist(Page plist) {
		Plist = plist;
	}

	@JSON(serialize = false)
	public XlsImportService getXlsImportService() {
		return xlsImportService;
	}

	public void setXlsImportService(XlsImportService xlsImportService) {
		this.xlsImportService = xlsImportService;
	}

	public String queryPayInput() {
		SysUser sysuer = (SysUser) getRequest().getSession().getAttribute(
				Constants.CURRENT_USER);
		HashMap<String, Object> paramap = new HashMap<String, Object>();
		Integer start = Parse.toInteger(getRequest().getParameter("start"), 0);
		Integer limit = Parse.toInteger(getRequest().getParameter("limit"), Constants.DEFAULT_PAGE_SIZE);
		String companyCode = sysuer.getCompanyCode();
		if (!"".equals(companyCode) || null != companyCode) {
			paramap.put("companyCode", sysuer.getCompanyCode());
			if (!"".equals(getRequest().getParameter("employeeName"))
					|| "null".equals(getRequest().getParameter("employeeName"))) {
				paramap.put("employeeName", getRequest().getParameter(
						"employeeName"));
			}
			if (!"".equals(getRequest().getParameter("period"))
					|| "null".equals(getRequest().getParameter("period"))) {
				paramap.put("period", getRequest().getParameter("period"));
			}
			if (!"".equals(getRequest().getParameter("emp_cs_code"))
					|| "null".equals(getRequest().getParameter("emp_cs_code"))) {
				paramap.put("employeeCode", getRequest().getParameter(
						"emp_cs_code"));
			}
			if (!"".equals(getRequest().getParameter("pay_class_id"))
					|| "null".equals(getRequest().getParameter("pay_class_id"))) {
				paramap.put("pay_class_id", getRequest().getParameter(
						"pay_class_id"));
			}
			if (!"".equals(getRequest().getParameter("pay_classitem_id"))
					|| "null".equals(getRequest().getParameter(
							"pay_classitem_id"))) {
				paramap.put("pay_classitem_id", getRequest().getParameter(
						"pay_classitem_id"));
			}

			Plist = xlsImportService.queryPayInputData(paramap, start, limit);
		} else {
			throw new RuntimeException("session过期或该用户没有客户编码");
		}
		return SUCCESS;
	}

	public String deletePayInput() {
		String deletelinkmanpar = getRequest().getParameter("deletelinkmanpar");
		if ("" != deletelinkmanpar || null != deletelinkmanpar) {
			deletelinkmanpar = deletelinkmanpar.substring(1, deletelinkmanpar
					.length() - 1);
			deletelinkmanpar = deletelinkmanpar.replace("\"", "'");
			System.out.println(deletelinkmanpar);
			try {
				xlsImportService.deletePayInputData(deletelinkmanpar);
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
		return SUCCESS;
	}

	public String deleteSocail() {
		String deleteSocail = getRequest().getParameter("deleteSocail");
		if ("" != deleteSocail || null != deleteSocail) {
			deleteSocail = deleteSocail.substring(1, deleteSocail.length() - 1);
			deleteSocail = deleteSocail.replace("\"", "'");
			System.out.println(deleteSocail);
			try {
				xlsImportService.deleteSocialResult(deleteSocail);
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
		return SUCCESS;
	}

	public String querySocial() {
		SysUser sysuer = (SysUser) getRequest().getSession().getAttribute(
				Constants.CURRENT_USER);
		HashMap<String, Object> paramap = new HashMap<String, Object>();
		Integer start = Parse.toInteger(getRequest().getParameter("start"), 0);
		Integer limit = Parse.toInteger(getRequest().getParameter("limit"), Constants.DEFAULT_PAGE_SIZE);
		String companyCode = sysuer.getCompanyCode();
		if ("".equals(companyCode) || null != companyCode) {
			paramap.put("companyCode", sysuer.getCompanyCode());
			if (!"".equals(getRequest().getParameter("employeeName"))
					|| "null".equals(getRequest().getParameter("employeeName"))) {
				paramap.put("employeeName", getRequest().getParameter(
						"employeeName"));
			}
			if (!"".equals(getRequest().getParameter("period"))
					|| "null".equals(getRequest().getParameter("period"))) {
				paramap.put("period", getRequest().getParameter("period"));
			}
			if (!"".equals(getRequest().getParameter("emp_cs_code"))
					|| "null".equals(getRequest().getParameter("emp_cs_code"))) {
				paramap.put("employeeCode", getRequest().getParameter(
						"emp_cs_code"));
			}
			if (!"".equals(getRequest().getParameter("socialSecurityId"))
					|| "null".equals(getRequest().getParameter(
							"socialSecurityId"))) {
				paramap.put("social_security_id", getRequest().getParameter(
						"socialSecurityId"));
			}

			Slist = xlsImportService.querySocialResult(paramap, start, limit);
		}
		return SUCCESS;
	}

	@JSON(serialize = false)
	public HttpServletRequest getRequest() {
		return ServletActionContext.getRequest();
	}

	public Page getSlist() {
		return Slist;
	}

	public void setSlist(Page slist) {
		Slist = slist;
	}
}
